<?php
require_once realpath (dirname (__FILE__) . '//..//pages.php');
require_once INC_FUNCTIONS;
require_once MDL_PERMISSIONS;

authorize ();
$db = openConnection ();
$models = array_keys (getModels ());
$users = $db->select ('user', array ('ID', 'username'));
?>
<html>
    <?php echo head (PAGE_TITLE, array (HTTP_CSS_MENU, HTTP_CSS_STYLE), array (HTTP_DIR_PHP_CALENDAR . '/scripts.js')); ?>
    <body>
        <?php require_once VW_MENU; ?>
        <form action="<?php HTTP_CTRL_MAIN; ?>" method="get">
            <label>Assegna il modello 
                <select name="model" size="<?php $n = count ($models); if ($n > 10) echo '10'; else if ($n > 3) echo $n; else echo '1'; ?>">
                    <?php foreach ($models as $model) : ?>
                        <option value="<?php echo $model; ?>"><?php echo $model; ?></option>
                    <?php endforeach; ?>        
                </select>
            </label>
            <label>all'utente
                <select name="IDuser" size="<?php $n =$db->numberOfRows ($users); if ($n > 10) echo '10'; else if ($n > 3) echo $n; else echo '1'; ?>">  
                    <?php while ($row = $db->fetchAssoc ($users)) : ?>
                        <option value="<?php echo $row['ID']; ?>"><?php echo $row['username']; ?></option> 
                    <?php endwhile; ?>
                </select>
            </label>
            <input name="account" type="hidden" value="assign"/>
            <button type="submit">Ok</button>
        </form>
    </body>
</html>